<!DOCTYPE html>
<html lang="en">
    <head>
        <title>地图定位导航</title>
        <meta charset="UTF-8"/>
        <meta name="viewport" content="width=device-width,initial-scale=1.0"/>
        <style rel="stylesheet" type="text/css">
            body{margin:0;padding:0;}
            #container{
                width: 100%;
                height: 100vh;
            }
        </style>
    </head>
    <body>
        <div id="container"></div>
        <script type="text/javascript">
            window._AMapSecurityConfig={
                securityJsCode:'141f9bc5881f73e63d7960acb1e36e99'
            };
        </script>
        <script
                src="https://webapi.amap.com/maps?v=2.0&key=0d240af1e6c8b0354794be62b7b3a504"
                type="text/javascript">
        </script>
        <script type="text/javascript">
            var map=new AMap.Map('container',{zoom:18,center:[121.474815,31.237216]});
            window.onload=function(){
                window.swift.setCurrentLocation();
            }
            function setLocation(lon,lat){
                map.setZoomAndCenter(20,[lon,lat]);
                var marker=new AMap.Marker({
                    map,
                    icon:'https://webapi.amap.com/theme/v1.3/markers/n/mark_b.png',
                    position:[lon,lat]
                });
                map.add(marker);
                //为地图新增插件能力：搜索
                map.plugin(['AMap.PlaceSearch'], function(){

                    //创建搜索功能对象，提供搜索设置
                    var MSearch = new AMap.PlaceSearch({
                        map,                //绑定的地图组件
                        pageSize: 4,        //每页多少条
                        pageIndex: 1,       //第几页
                        extensions: 'base'  //扩展：基本信息
                    });

                    //为地图设置监听：当搜索结果完成时
                    AMap.Event.addListener(MSearch, 'complete', (res)=>{
                        //调用鸿蒙方法，传回搜索结果
                        //通讯传递，只能是字符串string
                        window.swift.receiveNearPlace(JSON.stringify(res.poiList.pois));
                    });

                    //执行搜索：自动标记
                    MSearch.searchNearBy('停车场', [lon,lat]);
                });
            }
        </script>
    </body>
</html>